package com.atguigu.gulimall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import org.bouncycastle.asn1.x509.IetfAttrSyntax;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author kabuda
 * @create 2022-12-07 19:04
 */
@Data
public class OrderConfirmVo {

    //收获地址，ums——memberreceive——addressbiao
    List<MemberAddressVo> address;

    List<OrderItemVo> items;

    Integer integration; //优惠券信息

    BigDecimal total;  //订单总额
    BigDecimal payPrice;  //应付价格

    Map<Long, Boolean> stocks;
    //防重令牌
    String orderToken;

    public Integer getCount(){
        Integer i=0;
        if(items!=null&&items.size()>0) {
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        return getPayPrice();
    }

    public BigDecimal getPayPrice() {
        BigDecimal sum=BigDecimal.ZERO;
        if(items!=null&&items.size()>0){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum=sum.add(multiply);
            }
        }
        return sum;
    }
}
